# syntax=docker/dockerfile:1
FROM maven:3.9.6-eclipse-temurin-17 AS build
WORKDIR /app

# 复制父POM和common模块
COPY ../pom.xml ./
COPY ../common ./common

# 复制当前服务
COPY . ./data-service

# 构建
RUN mvn -q -f data-service/pom.xml clean package -DskipTests

FROM eclipse-temurin:17-jre
WORKDIR /app

# 安装CodeQL CLI（如果需要）
RUN apt-get update && apt-get install -y curl && \
    curl -L https://github.com/github/codeql-cli-binaries/releases/latest/download/codeql-linux64.zip -o codeql.zip && \
    unzip codeql.zip -d /opt && \
    rm codeql.zip && \
    apt-get clean && rm -rf /var/lib/apt/lists/*

ENV PATH="/opt/codeql:${PATH}"

# 复制JAR文件
COPY --from=build /app/data-service/target/*.jar app.jar

# 设置环境变量
ENV SPRING_PROFILES_ACTIVE=docker
ENV JAVA_OPTS="-Xms512m -Xmx2048m -XX:+UseG1GC"

# 暴露端口
EXPOSE 8085

# 健康检查
HEALTHCHECK --interval=30s --timeout=3s --start-period=40s --retries=3 \
  CMD curl -f http://localhost:8085/actuator/health || exit 1

# 启动应用
ENTRYPOINT ["sh", "-c", "java $JAVA_OPTS -jar app.jar"]
